--- /dev/null
+// Based on a file generated by gir. Changes are marked below.
+#[cfg(any(feature = "v2018_6", feature = "dox"))]
+use glib::translate::*;
+use glib_sys;
+use gobject_sys;
+use ostree_sys;
+use std::hash;
+
+glib_wrapper! {
+ #[derive(Debug, PartialOrd, Ord)]
+ pub struct CollectionRef(Boxed<ostree_sys::OstreeCollectionRef>);
+
+ match fn {
+ copy => |ptr| gobject_sys::g_boxed_copy(ostree_sys::ostree_collection_ref_get_type(), ptr as *mut _) as *mut ostree_sys::OstreeCollectionRef,
+ free => |ptr| gobject_sys::g_boxed_free(ostree_sys::ostree_collection_ref_get_type(), ptr as *mut _),
+ get_type => || ostree_sys::ostree_collection_ref_get_type(),
+ }
+}
+
+impl CollectionRef {
+ #[cfg(any(feature = "v2018_6", feature = "dox"))]
+ pub fn new(collection_id: Option<&str>, ref_name: &str) -> Option<CollectionRef> {
+ unsafe {
+ from_glib_full(ostree_sys::ostree_collection_ref_new(
+ collection_id.to_glib_none().0,
+ ref_name.to_glib_none().0,
+ ))
+ }
+ }
+
+ #[cfg(any(feature = "v2018_6", feature = "dox"))]
+ fn equal(&self, ref2: &CollectionRef) -> bool {
+ unsafe {
+ // CHANGE: both instances of *mut to *const
+ from_glib(ostree_sys::ostree_collection_ref_equal(
+ ToGlibPtr::<*const ostree_sys::OstreeCollectionRef>::to_glib_none(self).0
+ as glib_sys::gconstpointer,
+ ToGlibPtr::<*const ostree_sys::OstreeCollectionRef>::to_glib_none(ref2).0
+ as glib_sys::gconstpointer,
+ ))
+ }
+ }
+
+ #[cfg(any(feature = "v2018_6", feature = "dox"))]
+ fn hash(&self) -> u32 {
+ unsafe {
+ // CHANGE: *mut to *const
+ ostree_sys::ostree_collection_ref_hash(
+ ToGlibPtr::<*const ostree_sys::OstreeCollectionRef>::to_glib_none(self).0
+ as glib_sys::gconstpointer,
+ )
+ }
+ }
+}
+
+impl PartialEq for CollectionRef {
+ #[inline]
+ fn eq(&self, other: &Self) -> bool {
+ self.equal(other)
+ }
+}
+
+impl Eq for CollectionRef {}
+
+impl hash::Hash for CollectionRef {
+ #[inline]
+ fn hash<H>(&self, state: &mut H)
+ where
+ H: hash::Hasher,
+ {
+ hash::Hash::hash(&self.hash(), state)
+ }
+}
+++ /dev/null
-// Based on a file generated by gir. Changes are marked below.
-#[cfg(any(feature = "v2018_6", feature = "dox"))]
-use glib::translate::*;
-use glib_sys;
-use gobject_sys;
-use ostree_sys;
-use std::hash;
-
-glib_wrapper! {
- #[derive(Debug, PartialOrd, Ord)]
- pub struct CollectionRef(Boxed<ostree_sys::OstreeCollectionRef>);
-
- match fn {
- copy => |ptr| gobject_sys::g_boxed_copy(ostree_sys::ostree_collection_ref_get_type(), ptr as *mut _) as *mut ostree_sys::OstreeCollectionRef,
- free => |ptr| gobject_sys::g_boxed_free(ostree_sys::ostree_collection_ref_get_type(), ptr as *mut _),
- get_type => || ostree_sys::ostree_collection_ref_get_type(),
- }
-}
-
-impl CollectionRef {
- #[cfg(any(feature = "v2018_6", feature = "dox"))]
- pub fn new(collection_id: Option<&str>, ref_name: &str) -> Option<CollectionRef> {
- unsafe {
- from_glib_full(ostree_sys::ostree_collection_ref_new(
- collection_id.to_glib_none().0,
- ref_name.to_glib_none().0,
- ))
- }
- }
-
- #[cfg(any(feature = "v2018_6", feature = "dox"))]
- fn equal(&self, ref2: &CollectionRef) -> bool {
- unsafe {
- // CHANGE: both instances of *mut to *const
- from_glib(ostree_sys::ostree_collection_ref_equal(
- ToGlibPtr::<*const ostree_sys::OstreeCollectionRef>::to_glib_none(self).0
- as glib_sys::gconstpointer,
- ToGlibPtr::<*const ostree_sys::OstreeCollectionRef>::to_glib_none(ref2).0
- as glib_sys::gconstpointer,
- ))
- }
- }
-
- #[cfg(any(feature = "v2018_6", feature = "dox"))]
- fn hash(&self) -> u32 {
- unsafe {
- // CHANGE: *mut to *const
- ostree_sys::ostree_collection_ref_hash(
- ToGlibPtr::<*const ostree_sys::OstreeCollectionRef>::to_glib_none(self).0
- as glib_sys::gconstpointer,
- )
- }
- }
-}
-
-impl PartialEq for CollectionRef {
- #[inline]
- fn eq(&self, other: &Self) -> bool {
- self.equal(other)
- }
-}
-
-impl Eq for CollectionRef {}
-
-impl hash::Hash for CollectionRef {
- #[inline]
- fn hash<H>(&self, state: &mut H)
- where
- H: hash::Hasher,
- {
- hash::Hash::hash(&self.hash(), state)
- }
-}
-
-#[cfg(test)]
-mod tests;
+++ /dev/null
-use super::*;
-use std::collections::hash_map::DefaultHasher;
-use std::hash::{Hash, Hasher};
-
-fn hash(v: &impl Hash) -> u64 {
- let mut s = DefaultHasher::new();
- v.hash(&mut s);
- s.finish()
-}
-
-#[test]
-fn same_value_should_be_equal() {
- let r = CollectionRef::new(Some("io.gitlab.fkrull"), "ref").unwrap();
- assert_eq!(r, r);
-}
-
-#[test]
-fn equal_values_should_be_equal() {
- let a = CollectionRef::new(Some("io.gitlab.fkrull"), "ref").unwrap();
- let b = CollectionRef::new(Some("io.gitlab.fkrull"), "ref").unwrap();
- assert_eq!(a, b);
-}
-
-#[test]
-fn equal_values_without_collection_id_should_be_equal() {
- let a = CollectionRef::new(None, "ref-name").unwrap();
- let b = CollectionRef::new(None, "ref-name").unwrap();
- assert_eq!(a, b);
-}
-
-#[test]
-fn different_values_should_not_be_equal() {
- let a = CollectionRef::new(Some("io.gitlab.fkrull"), "ref1").unwrap();
- let b = CollectionRef::new(Some("io.gitlab.fkrull"), "ref2").unwrap();
- assert_ne!(a, b);
-}
-
-#[test]
-fn new_with_invalid_collection_id_should_return_none() {
- let r = CollectionRef::new(Some(".abc"), "ref");
- assert_eq!(r, None);
-}
-
-#[test]
-fn hash_for_equal_values_should_be_equal() {
- let a = CollectionRef::new(Some("io.gitlab.fkrull"), "ref").unwrap();
- let b = CollectionRef::new(Some("io.gitlab.fkrull"), "ref").unwrap();
- assert_eq!(hash(&a), hash(&b));
-}
-
-#[test]
-fn hash_for_values_with_different_collection_id_should_be_different() {
- let a = CollectionRef::new(Some("io.gitlab.fkrull1"), "ref").unwrap();
- let b = CollectionRef::new(Some("io.gitlab.fkrull2"), "ref").unwrap();
- assert_ne!(hash(&a), hash(&b));
-}
-
-#[test]
-fn hash_for_values_with_different_ref_id_should_be_different() {
- let a = CollectionRef::new(Some("io.gitlab.fkrull"), "ref-1").unwrap();
- let b = CollectionRef::new(Some("io.gitlab.fkrull"), "ref-2").unwrap();
- assert_ne!(hash(&a), hash(&b));
-}
-
-#[test]
-fn hash_should_be_different_if_collection_id_is_absent() {
- let a = CollectionRef::new(Some("io.gitlab.fkrull"), "ref").unwrap();
- let b = CollectionRef::new(None, "ref").unwrap();
- assert_ne!(hash(&a), hash(&b));
-}
-
-#[test]
-fn clone_should_be_equal_to_original_value() {
- let a = CollectionRef::new(Some("io.gitlab.fkrull"), "ref").unwrap();
- let b = a.clone();
- assert_eq!(a, b);
-}
use glib::Error;
-// re-exports
+// code generated by gir
mod auto;
pub use crate::auto::functions::*;
pub use crate::auto::*;
-mod repo;
-
+// handwritten code
#[cfg(any(feature = "v2018_6", feature = "dox"))]
mod collection_ref;
+mod repo;
#[cfg(any(feature = "v2018_6", feature = "dox"))]
-pub use crate::collection_ref::CollectionRef;
-
+pub use crate::collection_ref::*;
mod object_name;
-pub use crate::object_name::ObjectName;
+pub use crate::object_name::*;
+
+// tests
+#[cfg(test)]
+mod tests;
-// public modules
+// prelude
pub mod prelude {
pub use crate::auto::traits::*;
pub use crate::repo::RepoExtManual;
--- /dev/null
+use crate::Repo;
+#[cfg(any(feature = "v2016_4", feature = "dox"))]
+use crate::RepoListRefsExtFlags;
+use gio;
+use glib;
+use glib::translate::*;
+use glib::Error;
+use glib::IsA;
+use glib_sys;
+use ostree_sys;
+use std::collections::{HashMap, HashSet};
+use std::path::Path;
+use std::ptr;
+use ObjectName;
+
+unsafe extern "C" fn read_variant_table(
+ _key: glib_sys::gpointer,
+ value: glib_sys::gpointer,
+ hash_set: glib_sys::gpointer,
+) {
+ let value: glib::Variant = from_glib_none(value as *const glib_sys::GVariant);
+ let set: &mut HashSet<ObjectName> = &mut *(hash_set as *mut HashSet<ObjectName>);
+ set.insert(ObjectName::new_from_variant(value));
+}
+
+unsafe fn from_glib_container_variant_set(ptr: *mut glib_sys::GHashTable) -> HashSet<ObjectName> {
+ let mut set = HashSet::new();
+ glib_sys::g_hash_table_foreach(
+ ptr,
+ Some(read_variant_table),
+ &mut set as *mut HashSet<ObjectName> as *mut _,
+ );
+ glib_sys::g_hash_table_unref(ptr);
+ set
+}
+
+pub trait RepoExtManual {
+ fn new_for_path<P: AsRef<Path>>(path: P) -> Repo;
+
+ fn traverse_commit<P: IsA<gio::Cancellable>>(
+ &self,
+ commit_checksum: &str,
+ maxdepth: i32,
+ cancellable: Option<&P>,
+ ) -> Result<HashSet<ObjectName>, Error>;
+
+ // TODO: return GString?
+ fn list_refs<P: IsA<gio::Cancellable>>(
+ &self,
+ refspec_prefix: Option<&str>,
+ cancellable: Option<&P>,
+ ) -> Result<HashMap<String, String>, Error>;
+
+ #[cfg(any(feature = "v2016_4", feature = "dox"))]
+ fn list_refs_ext<P: IsA<gio::Cancellable>>(
+ &self,
+ refspec_prefix: Option<&str>,
+ flags: RepoListRefsExtFlags,
+ cancellable: Option<&P>,
+ ) -> Result<HashMap<String, String>, Error>;
+}
+
+impl<O: IsA<Repo>> RepoExtManual for O {
+ fn new_for_path<P: AsRef<Path>>(path: P) -> Repo {
+ Repo::new(&gio::File::new_for_path(path.as_ref()))
+ }
+
+ fn traverse_commit<P: IsA<gio::Cancellable>>(
+ &self,
+ commit_checksum: &str,
+ maxdepth: i32,
+ cancellable: Option<&P>,
+ ) -> Result<HashSet<ObjectName>, Error> {
+ unsafe {
+ let mut error = ptr::null_mut();
+ let mut hashtable = ptr::null_mut();
+ let _ = ostree_sys::ostree_repo_traverse_commit(
+ self.as_ref().to_glib_none().0,
+ commit_checksum.to_glib_none().0,
+ maxdepth,
+ &mut hashtable,
+ cancellable.map(|p| p.as_ref()).to_glib_none().0,
+ &mut error,
+ );
+ if error.is_null() {
+ Ok(from_glib_container_variant_set(hashtable))
+ } else {
+ Err(from_glib_full(error))
+ }
+ }
+ }
+
+ fn list_refs<P: IsA<gio::Cancellable>>(
+ &self,
+ refspec_prefix: Option<&str>,
+ cancellable: Option<&P>,
+ ) -> Result<HashMap<String, String>, Error> {
+ unsafe {
+ let mut error = ptr::null_mut();
+ let mut hashtable = ptr::null_mut();
+ let _ = ostree_sys::ostree_repo_list_refs(
+ self.as_ref().to_glib_none().0,
+ refspec_prefix.to_glib_none().0,
+ &mut hashtable,
+ cancellable.map(|p| p.as_ref()).to_glib_none().0,
+ &mut error,
+ );
+
+ if error.is_null() {
+ Ok(FromGlibPtrContainer::from_glib_container(hashtable))
+ } else {
+ Err(from_glib_full(error))
+ }
+ }
+ }
+
+ #[cfg(any(feature = "v2016_4", feature = "dox"))]
+ fn list_refs_ext<P: IsA<gio::Cancellable>>(
+ &self,
+ refspec_prefix: Option<&str>,
+ flags: RepoListRefsExtFlags,
+ cancellable: Option<&P>,
+ ) -> Result<HashMap<String, String>, Error> {
+ unsafe {
+ let mut error = ptr::null_mut();
+ let mut hashtable = ptr::null_mut();
+ let _ = ostree_sys::ostree_repo_list_refs_ext(
+ self.as_ref().to_glib_none().0,
+ refspec_prefix.to_glib_none().0,
+ &mut hashtable,
+ flags.to_glib(),
+ cancellable.map(|p| p.as_ref()).to_glib_none().0,
+ &mut error,
+ );
+
+ if error.is_null() {
+ Ok(FromGlibPtrContainer::from_glib_container(hashtable))
+ } else {
+ Err(from_glib_full(error))
+ }
+ }
+ }
+}
+++ /dev/null
-use crate::Repo;
-#[cfg(any(feature = "v2016_4", feature = "dox"))]
-use crate::RepoListRefsExtFlags;
-use gio;
-use glib;
-use glib::translate::*;
-use glib::Error;
-use glib::IsA;
-use glib_sys;
-use ostree_sys;
-use std::collections::{HashMap, HashSet};
-use std::path::Path;
-use std::ptr;
-use ObjectName;
-
-unsafe extern "C" fn read_variant_table(
- _key: glib_sys::gpointer,
- value: glib_sys::gpointer,
- hash_set: glib_sys::gpointer,
-) {
- let value: glib::Variant = from_glib_none(value as *const glib_sys::GVariant);
- let set: &mut HashSet<ObjectName> = &mut *(hash_set as *mut HashSet<ObjectName>);
- set.insert(ObjectName::new_from_variant(value));
-}
-
-unsafe fn from_glib_container_variant_set(ptr: *mut glib_sys::GHashTable) -> HashSet<ObjectName> {
- let mut set = HashSet::new();
- glib_sys::g_hash_table_foreach(
- ptr,
- Some(read_variant_table),
- &mut set as *mut HashSet<ObjectName> as *mut _,
- );
- glib_sys::g_hash_table_unref(ptr);
- set
-}
-
-pub trait RepoExtManual {
- fn new_for_path<P: AsRef<Path>>(path: P) -> Repo;
-
- fn traverse_commit<P: IsA<gio::Cancellable>>(
- &self,
- commit_checksum: &str,
- maxdepth: i32,
- cancellable: Option<&P>,
- ) -> Result<HashSet<ObjectName>, Error>;
-
- // TODO: return GString?
- fn list_refs<P: IsA<gio::Cancellable>>(
- &self,
- refspec_prefix: Option<&str>,
- cancellable: Option<&P>,
- ) -> Result<HashMap<String, String>, Error>;
-
- #[cfg(any(feature = "v2016_4", feature = "dox"))]
- fn list_refs_ext<P: IsA<gio::Cancellable>>(
- &self,
- refspec_prefix: Option<&str>,
- flags: RepoListRefsExtFlags,
- cancellable: Option<&P>,
- ) -> Result<HashMap<String, String>, Error>;
-}
-
-impl<O: IsA<Repo>> RepoExtManual for O {
- fn new_for_path<P: AsRef<Path>>(path: P) -> Repo {
- Repo::new(&gio::File::new_for_path(path.as_ref()))
- }
-
- fn traverse_commit<P: IsA<gio::Cancellable>>(
- &self,
- commit_checksum: &str,
- maxdepth: i32,
- cancellable: Option<&P>,
- ) -> Result<HashSet<ObjectName>, Error> {
- unsafe {
- let mut error = ptr::null_mut();
- let mut hashtable = ptr::null_mut();
- let _ = ostree_sys::ostree_repo_traverse_commit(
- self.as_ref().to_glib_none().0,
- commit_checksum.to_glib_none().0,
- maxdepth,
- &mut hashtable,
- cancellable.map(|p| p.as_ref()).to_glib_none().0,
- &mut error,
- );
- if error.is_null() {
- Ok(from_glib_container_variant_set(hashtable))
- } else {
- Err(from_glib_full(error))
- }
- }
- }
-
- fn list_refs<P: IsA<gio::Cancellable>>(
- &self,
- refspec_prefix: Option<&str>,
- cancellable: Option<&P>,
- ) -> Result<HashMap<String, String>, Error> {
- unsafe {
- let mut error = ptr::null_mut();
- let mut hashtable = ptr::null_mut();
- let _ = ostree_sys::ostree_repo_list_refs(
- self.as_ref().to_glib_none().0,
- refspec_prefix.to_glib_none().0,
- &mut hashtable,
- cancellable.map(|p| p.as_ref()).to_glib_none().0,
- &mut error,
- );
-
- if error.is_null() {
- Ok(FromGlibPtrContainer::from_glib_container(hashtable))
- } else {
- Err(from_glib_full(error))
- }
- }
- }
-
- #[cfg(any(feature = "v2016_4", feature = "dox"))]
- fn list_refs_ext<P: IsA<gio::Cancellable>>(
- &self,
- refspec_prefix: Option<&str>,
- flags: RepoListRefsExtFlags,
- cancellable: Option<&P>,
- ) -> Result<HashMap<String, String>, Error> {
- unsafe {
- let mut error = ptr::null_mut();
- let mut hashtable = ptr::null_mut();
- let _ = ostree_sys::ostree_repo_list_refs_ext(
- self.as_ref().to_glib_none().0,
- refspec_prefix.to_glib_none().0,
- &mut hashtable,
- flags.to_glib(),
- cancellable.map(|p| p.as_ref()).to_glib_none().0,
- &mut error,
- );
-
- if error.is_null() {
- Ok(FromGlibPtrContainer::from_glib_container(hashtable))
- } else {
- Err(from_glib_full(error))
- }
- }
- }
-}
-
-#[cfg(test)]
-mod tests;
+++ /dev/null
-use super::*;
-use crate::RepoMode;
-
-#[test]
-fn should_get_repo_mode_from_string() {
- let mode = Repo::mode_from_string("archive").unwrap();
- assert_eq!(RepoMode::Archive, mode);
-}
-
-#[test]
-fn should_return_error_for_invalid_repo_mode_string() {
- let result = Repo::mode_from_string("invalid-repo-mode");
- assert!(result.is_err());
-}
\ No newline at end of file
--- /dev/null
+use crate::CollectionRef;
+use std::collections::hash_map::DefaultHasher;
+use std::hash::{Hash, Hasher};
+
+fn hash(v: &impl Hash) -> u64 {
+ let mut s = DefaultHasher::new();
+ v.hash(&mut s);
+ s.finish()
+}
+
+#[test]
+fn same_value_should_be_equal() {
+ let r = CollectionRef::new(Some("io.gitlab.fkrull"), "ref").unwrap();
+ assert_eq!(r, r);
+}
+
+#[test]
+fn equal_values_should_be_equal() {
+ let a = CollectionRef::new(Some("io.gitlab.fkrull"), "ref").unwrap();
+ let b = CollectionRef::new(Some("io.gitlab.fkrull"), "ref").unwrap();
+ assert_eq!(a, b);
+}
+
+#[test]
+fn equal_values_without_collection_id_should_be_equal() {
+ let a = CollectionRef::new(None, "ref-name").unwrap();
+ let b = CollectionRef::new(None, "ref-name").unwrap();
+ assert_eq!(a, b);
+}
+
+#[test]
+fn different_values_should_not_be_equal() {
+ let a = CollectionRef::new(Some("io.gitlab.fkrull"), "ref1").unwrap();
+ let b = CollectionRef::new(Some("io.gitlab.fkrull"), "ref2").unwrap();
+ assert_ne!(a, b);
+}
+
+#[test]
+fn new_with_invalid_collection_id_should_return_none() {
+ let r = CollectionRef::new(Some(".abc"), "ref");
+ assert_eq!(r, None);
+}
+
+#[test]
+fn hash_for_equal_values_should_be_equal() {
+ let a = CollectionRef::new(Some("io.gitlab.fkrull"), "ref").unwrap();
+ let b = CollectionRef::new(Some("io.gitlab.fkrull"), "ref").unwrap();
+ assert_eq!(hash(&a), hash(&b));
+}
+
+#[test]
+fn hash_for_values_with_different_collection_id_should_be_different() {
+ let a = CollectionRef::new(Some("io.gitlab.fkrull1"), "ref").unwrap();
+ let b = CollectionRef::new(Some("io.gitlab.fkrull2"), "ref").unwrap();
+ assert_ne!(hash(&a), hash(&b));
+}
+
+#[test]
+fn hash_for_values_with_different_ref_id_should_be_different() {
+ let a = CollectionRef::new(Some("io.gitlab.fkrull"), "ref-1").unwrap();
+ let b = CollectionRef::new(Some("io.gitlab.fkrull"), "ref-2").unwrap();
+ assert_ne!(hash(&a), hash(&b));
+}
+
+#[test]
+fn hash_should_be_different_if_collection_id_is_absent() {
+ let a = CollectionRef::new(Some("io.gitlab.fkrull"), "ref").unwrap();
+ let b = CollectionRef::new(None, "ref").unwrap();
+ assert_ne!(hash(&a), hash(&b));
+}
+
+#[test]
+fn clone_should_be_equal_to_original_value() {
+ let a = CollectionRef::new(Some("io.gitlab.fkrull"), "ref").unwrap();
+ let b = a.clone();
+ assert_eq!(a, b);
+}
--- /dev/null
+mod collection_ref;
+mod repo;
--- /dev/null
+use crate::Repo;
+use crate::RepoMode;
+
+#[test]
+fn should_get_repo_mode_from_string() {
+ let mode = Repo::mode_from_string("archive").unwrap();
+ assert_eq!(RepoMode::Archive, mode);
+}
+
+#[test]
+fn should_return_error_for_invalid_repo_mode_string() {
+ let result = Repo::mode_from_string("invalid-repo-mode");
+ assert!(result.is_err());
+}